package stud.aistar.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import stud.aistar.entity.*;
import stud.aistar.mapper.UserInfoMapper;
import stud.aistar.service.IUserInfoService;
import stud.aistar.vo.AgeVo;

import java.util.List;

/**
 * @version 1.0
 * @Auther: git:jybdd - liming
 * @Description - 本类用于: 个人中心service实现类
 * @Date: 2019/9/28 19:29
 */
@Service
@Transactional
public class UserInfoServiceImpl implements IUserInfoService {

    @Autowired
    private UserInfoMapper mapper;


    /**
     * 用于根据用户的id来获取User的详情信息
     * @param id
     */
    @Override
    public Userinfo findByUserId(Integer id) {
        Userinfo userinfo = mapper.findByUserId(id);
        return userinfo;
    }

    /**
     * 用户添加个人资料,重要资料需要一次性填写完整
     * @param userinfo
     */
    @Override
    public void save(Userinfo userinfo) {
        mapper.save(userinfo);
    }

    /**
     * 查询用户信息
     * @param id
     * @return
     */
    @Override
    public User findById(Integer id) {
        User user = mapper.findById(id);
        return user;
    }

    /**
     * 在个人中心更改用户名,密码,手机号..
     * @param user
     */
    @Override
    public void update(User user) {
        mapper.update(user);
    }

    @Override
    public void saveUser(User user) {
        mapper.saveUser(user);
    }

    @Override
    public AgeVo findCardYear(String str) {
        AgeVo ageVo = mapper.findCardYear(str);
        return ageVo;
    }

    @Override
    public List<Userinfo> findByTypes(Integer id) {
        List<Userinfo> userinfo = mapper.findByTypes(id);
        return userinfo;
    }

    @Override
    public PageInfo<Userinfo> findReplace(Integer id, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Userinfo> userinfos = mapper.findReplace(id);
        PageInfo<Userinfo> pageInfo = new PageInfo<>(userinfos);
        return pageInfo;
    }

    @Override
    public List<Userinfo> findReplace(Integer id) {
        List<Userinfo> userinfo = mapper.findByTypes(id);
        return userinfo;
    }

    @Override
    public Userinfo findByUserInfoId(Integer id) {
        Userinfo userinfo = mapper.findByUserInfoId(id);
        return userinfo;
    }

    @Override
    public List<Userinfo> findAllByUserId(Integer id) {
        List<Userinfo> userinfos =mapper.findAllByUserId(id);
        return userinfos;
    }

    /**
     * 记数
     * @param id
     * @return
     */
    @Override
    public Integer CountPeopleByUserId(Integer id) {
        Integer count = mapper.CountPeopleByUserId(id);
        return count;
    }

    @Override
    public void delByUserInfoId(Userinfo userinfo) {
        mapper.delByUserInfoId(userinfo);
    }

    @Override
    public Phone findByPhoneId(Integer id) {
        Phone phone = mapper.findByPhoneId(id);
        return phone;
    }

    @Override
    public void updatePhone(Phone phone) {
        mapper.updatePhone(phone);
    }

}
